package com.blt.car.me.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.blt.car.R;
import com.blt.car.journey.ExchangeComplaintActivity;
import com.blt.car.utils.ActivityHelper;
import com.blt.car.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

import blt.app_core.api.journey.bean.AppealInfo;
import blt.app_core.api.journey.bean.ExtrasVo;


/**
 * Created by xgp on 2017/6/24.
 */

public class ComplaintAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private Context context;
    List<AppealInfo> appealInfos = new ArrayList<>();

    public ComplaintAdapter(Context context) {
        inflater = LayoutInflater.from(context);
        this.context = context;
    }

    public void addData(List<AppealInfo> data) {
        appealInfos.addAll(data);
        notifyDataSetChanged();
    }

    public void clear() {
        appealInfos.clear();
    }

    @Override
    public int getCount() {
        return appealInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return appealInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View v, ViewGroup parent) {
        AppealHolder holder;
        if (v == null) {
            v = inflater.inflate(R.layout.item_complaint, parent, false);
            holder = new AppealHolder();
            v.setTag(holder);
        } else {
            holder = (AppealHolder) v.getTag();
        }
        holder.billNo = (TextView) v.findViewById(R.id.complaint_bill_no);
        holder.time = (TextView) v.findViewById(R.id.item_complaint_time);
        holder.modifyAppleal = (Button) v.findViewById(R.id.item_complaint_modify);

        holder.billNo.setText(appealInfos.get(position).travelOrderId + "");
        holder.time.setText(StringUtils.getDay(appealInfos.get(position).createTime));

        holder.modifyAppleal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ExtrasVo vo = new ExtrasVo();
                vo.travelId = appealInfos.get(position).travelOrderId;
                vo.appealInfo = appealInfos.get(position);
                vo.type = 3;
                ExchangeComplaintActivity.start(context, vo);
            }
        });

        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityHelper.toComplaintDetail(context, appealInfos.get(position));
            }
        });

        return v;
    }


    class AppealHolder {
        TextView billNo;
        TextView time;
        Button modifyAppleal;
    }


}
